package com.ruoyi.client.controller;

import com.ruoyi.client.pojo.vo.HomeCarouselVo;
import com.ruoyi.client.pojo.vo.HomeGoodsVo;
import com.ruoyi.client.pojo.vo.HomeInfoVo;
import com.ruoyi.client.service.IHomeService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 首页接口Controller
 *
 * @author HuaQP
 * @date 2024-09-14
 */
@Anonymous
@Api(tags = "01.首页接口")
@RestController("ClientHomeController")
@RequestMapping("/home")
public class HomeController extends BaseController
{
    @Resource
    private IHomeService homeService;

    /**
     * 查询首页数据
     */
    @ApiOperation("获取首页数据")
    @GetMapping("/index")
    public R<HomeInfoVo> index()
    {
        // /1 轮播  / 2为你推荐  /3新品上线  /4热销商品
        //获取轮播数据
        List<HomeCarouselVo>  carouselList = homeService.getCarouselList();
        // 获取首页推荐
        List<HomeGoodsVo> recommendGoodsList = homeService.getHomeGoodsList(2);
        // 获取新品数据
        List<HomeGoodsVo> newGoodsList = homeService.getHomeGoodsList(3);
        // 获取热销商品
        List<HomeGoodsVo> hotGoodsList = homeService.getHomeGoodsList(4);

        HomeInfoVo homeInfoVo = new HomeInfoVo();

        homeInfoVo.setCarouselList(carouselList);
        homeInfoVo.setRecommendGoodsList(recommendGoodsList);
        homeInfoVo.setNewGoodsList(newGoodsList);
        homeInfoVo.setHotGoodsList(hotGoodsList);
        return R.ok(homeInfoVo);
    }

}
